// pages/liveSale/liveSale.js
Page({

  /**
   * 页面的初始数据
   */
  data: {
    // 直播热卖导航数据
    navList: [
      {
        "text": "热门",
        "id": 0
      },
      {
        "text": "最新",
        "id": 1
      },
      {
        "text": "关注",
        "id": 2
      },
      {
        "text": "美妆",
        "id": 3
      },
      {
        "text": "穿搭",
        "id": 4
      }
    ],
    currentIndexNav: 0, // 被点击菜单索引
    // 下划线css属性
    lineLeft: 0,
    lineWidth: 0,
    // 数据
    videosList: [
      {
        "id": 0,
        "live": "直播中",
        "num": "7876",
        "praise": "254",
        "liveImg": "/images/live-player-page.png",
        "title": "猫人品牌直接减年货节",
        "anchor": "MJ_啵姐",
        "goodsImg": [
          "/images/goods/goods.jpg",
          "/images/goods/goods1.jpg",
          "/images/goods/goods2.jpg",
          "/images/goods/goods9.jpg",
          "/images/goods/goods3.jpg"
        ]
      },
      {
        "id": 1,
        "live": "直播中",
        "num": "894",
        "praise": "45",
        "liveImg": "/images/live/1.jpg",
        "title": "年底女鞋疯狂秒",
        "anchor": "Sweet阿欢",
        "goodsImg": [
          "/images/goods/goods4.jpg",
          "/images/goods/goods5.jpg",
          "/images/goods/goods6.jpg",
          "/images/goods/goods7.jpg",
          "/images/goods/goods9.jpg",
          "/images/goods/goods1.jpg"
        ]
      },
      {
        "id": 2,
        "live": "直播中",
        "num": "456",
        "praise": "7812",
        "liveImg": "/images/live/2.jpg",
        "title": "卫衣包邮",
        "anchor": "星蓝",
        "goodsImg": [
          "/images/goods/goods8.jpg",
          "/images/goods/goods9.jpg",
          "/images/goods/goods1.jpg",
          "/images/goods/goods2.jpg"
        ]
      },
      {
        "id": 3,
        "live": "直播中",
        "num": "324",
        "praise": "43",
        "liveImg": "/images/live/3.jpg",
        "title": "护肤9.9起",
        "anchor": "秀宝",
        "goodsImg": [
          "/images/goods/goods.jpg",
          "/images/goods/goods9.jpg"
        ]
      },
      {
        "id": 4,
        "live": "直播中",
        "num": "324",
        "praise": "12",
        "liveImg": "/images/live/4.jpg",
        "title": "板鞋秒杀",
        "anchor": "宝儿姐",
        "goodsImg": [
          "/images/goods/goods8.jpg",
          "/images/goods/goods3.jpg",
          "/images/goods/goods9.jpg",
          "/images/goods/goods1.jpg",
          "/images/goods/goods7.jpg",
          "/images/goods/goods5.jpg"
        ]
      },
      {
        "id": 5,
        "live": "直播中",
        "num": "324",
        "praise": "234",
        "liveImg": "/images/live/5.jpg",
        "title": "零食特价",
        "anchor": "若微",
        "goodsImg": [
          "/images/goods/goods1.jpg",
          "/images/goods/goods2.jpg",
          "/images/goods/goods6.jpg",
          "/images/goods/goods9.jpg"
        ]
      },
      {
        "id": 6,
        "live": "直播中",
        "num": "2312",
        "praise": "23",
        "liveImg": "/images/live/6.jpg",
        "title": "女士卫衣",
        "anchor": "星蓝",
        "goodsImg": [
          "/images/goods/goods.jpg",
          "/images/goods/goods3.jpg",
          "/images/goods/goods6.jpg",
          "/images/goods/goods9.jpg"
        ]
      }
    ]
  },

  // 当前导航选项添加下划线
  activeBottomLine(index) {
    let self = this
    wx.createSelectorQuery().select(`#nav${index}`).boundingClientRect((res) => {
      self.setData({
        lineWidth: parseInt(res.width),
        lineLeft: parseInt(res.left)
      })
    })
  },

  // 点击首页导航按钮
  activeNav(e) {
    // 给菜单设置下划线
    this.activeBottomLine(e.target.dataset.index)
    this.setData({
      currentIndexNav: e.target.dataset.index
    })
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {

  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})